package com.qn.visitor.analyze.resolver;

import com.qn.visitor.model.UserVisitorRequest;
import com.qn.visitor.model.bo.analyze.ClientLanguageModel;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */
@Component
public class ClientLanguageResolver  implements IResolver<List<ClientLanguageModel>>{
    @Override
    public List<ClientLanguageModel> rsolver(UserVisitorRequest ubrBo) throws Exception {
        String str=ubrBo.getClientLanguage();
        int limit=-1;
        List<ClientLanguageModel> list=new ArrayList<>();
        Integer dh=  str.indexOf(",");
        if(dh==null&&dh.equals(-1))
        {
            list.add(new ClientLanguageModel(str,1.0));
        }
        String[] clarr=str.split(",",limit);
        for (int i=0;i<clarr.length;i++)
        {
            Integer dhs=  clarr[i].indexOf(";");
            if(dhs.equals(-1))
            {
                list.add(new ClientLanguageModel(clarr[i],1.0));
                continue;
            }
            String[] clitemarr=clarr[i].split(";",limit);
            if(clitemarr.length<=1)
            {
                list.add(new ClientLanguageModel(clarr[i],0.0));
                continue;
            }
            Integer dengy=  clitemarr[1].indexOf("=");
            String[] priorityarr=clarr[i].split("=",limit);
            if(dengy.equals(-1)&&priorityarr.length>1)
            {
                list.add(new ClientLanguageModel(clarr[i],0.0));
                continue;
            }
            list.add(new ClientLanguageModel(clitemarr[0],Double.valueOf(priorityarr[1])));

        }
        return list;
    }
}
